def processurl(machine, dirs, version):
  if machine.isLinux():
    return "http://downloads.sourceforge.net/project/glew/glew/%(VERSION)s/glew-%(VERSION)s.tgz" % {"VERSION":version}
  else:
    return "http://downloads.sourceforge.net/project/glew/glew/%(VERSION)s/glew-%(VERSION)s-win%(BITS)s.zip"  % {"BITS" :str(machine.bits),  "VERSION":version}

VERSIONS = ["1.5.3"]
DEFAULT_VERSION = "1.5.3"
URL = processurl

import os
from source.builders import DownloadAndCopyBuilder, GenericBuilder 
from subprocess import Popen

class GlewBuilder( GenericBuilder ):
  """ subclass of ConfigureMakeBuilder with a GLEW_DEST """

  def configure(self):
    os.chdir( self.extractedpath )
    self.dos2unix("Makefile")
    self.dos2unix("config/config.guess")

  def install(self):
    os.chdir( self.extractedpath )
    glewenv = os.environ
    glewenv['GLEW_DEST'] = self.installpath()
    os.makedirs(self.installpath() + "/lib64/pkgconfig")
    os.makedirs(self.installpath() + "/lib/pkgconfig")
    Popen( "make install", shell=True, env=glewenv ).wait()

def decider( machine, dirs ):
  if machine.isLinux():  
    return GlewBuilder
  else:
    return DownloadAndCopyBuilder

BUILDER = decider
